home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1994 November / Cd Ware (Nro. 2) - Epimundo.iso / DOS / DB / DGROUP.ZIP / DG_UTIL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-04  |  6.0 KB  |  156 lines

  1. /*
  2. ** DG_UTIL - version 2.0
  3. **
  4. ** The following routines are for monitoring the status of the portion of
  5. ** DGROUP which is allocated at run-time, which is known as the the Eval
  6. ** Stack and Memvar Table.
  7. **
  8. ** Copyright(C) 1993, Robert G. Montgomery.  All Right Reserved.
  9. ** 
  10. ** You are hereby granted rights to include this function in your application
  11. ** programs, free of charge, and if deemed necessary, you may also distribute
  12. ** the source for the function with the source for any applications which use
  13. ** them, free of charge.
  14. **
  15. ** The routines will only work with Clipper version 5.2, but may work with
  16. ** later versions as well.
  17. **
  18. ** The routines are based on UNDOCUMENTED public variables defined in
  19. ** CLIPPER.LIB.  Therefore, they probably will not work in some future
  20. ** version of Clipper.  They are provided for use in helping to debug
  21. ** applications written in Clipper 5.2.  Do not write programs which depend
  22. ** on them, only use them for debugging programs.  It is very possible
  23. ** that these routines will work in future versions of Clipper, but it
  24. ** would be a bad idea to count on that.
  25. **
  26. ** These functions will only work with Clipper 5.2 or later.
  27. */
  28.  
  29. #include "extend.api"
  30. #include "item.api"
  31. #include "vm.api"
  32.  
  33. /*
  34. ** declarations of Clipper internal variables defined in CLIPPER.LIB.
  35. */
  36.  
  37. extern ITEM _evalhigh; /* 1 - current high water mark for the Eval Stack  */
  38. extern ITEM _estatlow; /* 2 - current low water mark for the Memvar Table */
  39. extern ITEM _eval;     /* 3 - return value from last function call        */
  40. extern ITEM _tos;      /* 4 - current top of Eval Stack                   */
  41. extern ITEM _estat;    /* 5 - current low end of Memvar Table             */
  42. extern ITEM _eextent;  /* 6 - current high end of Memvar Table            */
  43. extern ITEM _lbase;    /* 7 - address of first local variable for current */
  44.                        /*     function/procedure executing                */
  45.  
  46. /*
  47. ** DG_numbers() - returns a 7 element array containing the above DGROUP
  48. ** values.  The type ITEM is really a near pointer to a void.  This routine
  49. ** returns an array of 7 integers, each integer is the result of type-casting
  50. ** the above UNDOCUMENTED near pointer variables to an integer.  Therefore,
  51. ** each number is an offset from the beginning of DGROUP.  The numbers are
  52. ** inserted into the array in the order listed above.
  53. */
  54.  
  55. CLIPPER DG_numbers () {
  56.   ITEM tmp, tmp_arr;
  57.   tmp_arr = _itemArrayNew(7);
  58.   tmp = _itemPutNL(NULL,(USHORT)_evalhigh);
  59.   tmp_arr = _itemArrayPut(tmp_arr,1,tmp);
  60.   tmp = _itemPutNL(tmp,(USHORT)_estatlow);
  61.   tmp_arr = _itemArrayPut(tmp_arr,2,tmp);
  62.   tmp = _itemPutNL(tmp,(USHORT)_eval);
  63.   tmp_arr = _itemArrayPut(tmp_arr,3,tmp);
  64.   tmp = _itemPutNL(tmp,(USHORT)_tos);
  65.   tmp_arr = _itemArrayPut(tmp_arr,4,tmp);
  66.   tmp = _itemPutNL(tmp,(USHORT)_estat);
  67.   tmp_arr = _itemArrayPut(tmp_arr,5,tmp);
  68.   tmp = _itemPutNL(tmp,(USHORT)_eextent);
  69.   tmp_arr = _itemArrayPut(tmp_arr,6,tmp);
  70.   tmp = _itemPutNL(tmp,(USHORT)_lbase);
  71.   tmp_arr = _itemArrayPut(tmp_arr,7,tmp);
  72.   _itemRelease(tmp);
  73.   _itemRelease(_itemReturn(tmp_arr));
  74.   }
  75.  
  76. /*
  77. ** DG_statics - returns an array holding the values all variables defined
  78. ** in the Memvar Table, which means all static variables and all values
  79. ** associated with all ITEMs defined through ITEM.API.  USE THIS ROUTINE
  80. ** ONLY FOR DEBUGGING PURPOSES, do not include it as part of your
  81. ** final run-time version of your program, except to use for on-site
  82. ** debugging.  This routine is based on UNDOCUMENTED internal information,
  83. ** therefore, it may not work in future releases of Clipper.
  84. **
  85. ** Note that this routine creates its own static variables which will also
  86. ** appear in the list.  Also, there will be some empty slots in the list
  87. ** which contain nil values, as well as used slots which contain nil values.
  88. ** I have not determined how to tell if a slot is used or not.  I believe
  89. ** Clipper maintains a separate table for bookkeeping the allocations and
  90. ** deallocations of ITEMS.
  91. */
  92.  
  93. CLIPPER DG_statics () {
  94.   ITEM arr;
  95.   USHORT ii, jj = 1;
  96.   ii = (USHORT)_eextent - (USHORT)_estat;
  97.   arr = _itemArrayNew((ii/14)+1);
  98.   for (ii=(USHORT)_eextent;ii>=(USHORT)_estat;ii-=14) {
  99.     if (ii!=(USHORT)arr) 
  100.       arr = _itemArrayPut(arr,jj,(ITEM)ii);
  101.     jj++;
  102.     }
  103.   _itemRelease(_itemReturn(arr));
  104.   }
  105.  
  106. /*
  107. ** DG_statHex - returns an array holding a HEX representation of the 14
  108. ** bytes which are stored in DGROUP for all static variables and ITEMs
  109. ** currently allocated to a program, which are defined in the Memvar Table.
  110. ** USE THIS ROUTINE ONLY FOR DEBUGGING PURPOSES, do not include it as part
  111. ** of your final run-time version of your program, except to use for on-site
  112. ** debugging.  The routine is based on UNDOCUMENTED 
  113. **
  114. ** Note that this routine creates its own static variables which will also
  115. ** appear in the list.  Also, there will be some empty slots in the list
  116. ** which contain nil values, as well as used slots which contain nil values.
  117. ** I have not determined how to tell if a slot is used or not.  I believe
  118. ** Clipper maintains a separate table for bookkeeping the allocations and
  119. ** deallocations of ITEMS.
  120. */
  121.  
  122. unsigned char dg_hex(BYTE x) {
  123.   if (x>=10)
  124.     return 55+x;
  125.   else
  126.     return 48+x;
  127.   }
  128.  
  129. CLIPPER DG_statHex () {
  130.   ITEM arr, tmp, iptr;
  131.   USHORT ii, jj = 1, kk;
  132.   unsigned char _near * ptr;
  133.   HANDLE buffhandl;
  134.   BYTEP tmpbuff;
  135.   ii = (USHORT)_eextent - (USHORT)_estat;
  136.   arr = _itemArrayNew((ii/14)+1);
  137.   tmp = _itemNew(NULL);
  138.   buffhandl = _xvalloc(28,0);
  139.   tmpbuff = _xvlock(buffhandl);
  140.   for (iptr=_eextent;iptr>_estat;(unsigned char _near *)iptr-=14) {
  141.     if (iptr!=arr&&iptr!=tmp) {
  142.       ptr = (unsigned char _near *)iptr;
  143.       for (kk=0;kk<14;kk++) {
  144.         tmpbuff[kk*2]=dg_hex((*ptr)>>4);
  145.         tmpbuff[kk*2+1]=dg_hex((*ptr++)&0xF);
  146.         }
  147.       arr = _itemArrayPut(arr,jj,tmp=_itemPutCL(tmp,tmpbuff,28));
  148.       }
  149.     jj++;
  150.     }
  151.   _itemRelease(_itemReturn(arr));
  152.   _itemRelease(tmp);
  153.   _xvunlock(buffhandl);
  154.   _xvfree(buffhandl);
  155.   }
  156.